;
(function() {
	var role = require("./role");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var AdminCon = require("../../core/admin/_con");
	var DotnarNewsCon = require("../../core/dotnar_news/_con");
	var ResponObj = require("../_include/responObj");
	module.exports = {
		prefix: "/news",
		get: {
			"/byId": function() {
				var query = this.query;
				var news_id = query.news_id;
				if (!news_id) {
					throwCusError("参数错误")
				}
				var dotnar_news = DotnarNewsCon.get(news_id);
				if (!dotnar_news) {
					throwCusError("找不到指定动态")
				}
				this.body = ResponObj("json", dotnar_news);
			},
			"/list": function() {
				var query = this.query;
				var dotnar_news_list = DotnarNewsCon.getAll(query.num, query.page);
				this.body = ResponObj("json", dotnar_news_list);
			},
		},
		post: {
			"/add_news": function() {
				var news_info = this.request.body;
				var admin = role.getAdmin(this);
				var news_id = admin.addNews(news_info);
				this.body = ResponObj("json", DotnarNewsCon.get(news_id));
			},
		},
		put: {
			"/update_news": function() {
				var dotnar_news = this.request.body;
				var news_id = dotnar_news.news_id;
				var news_info = dotnar_news.info;
				if (!(news_id && news_info)) {
					throwCusError("参数错误");
				}
				var admin = role.getAdmin(this);
				admin.updateNews(news_id, news_info);
				this.body = ResponObj("json", DotnarNewsCon.get(news_id));
			}
		},
		"delete": {
			"/remove_news": function() {
				var body = this.request.body;
				var news_id = body.news_id;
				if (!news_id) {
					throwCusError("参数错误")
				}
				var admin = role.getAdmin(this);
				admin.removeNews(news_id);
				return module.exports.get["/list"].apply(this, arguments);
			},
		}
	}
}());